package com.team7.happycommunity.businessservice.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class RabbitMQConfig {

   @Bean
    public Queue queue(){
       Map map=new HashMap<>();
       map.put("x-dead-letter-exchange","phone_code_dead_exchange");
       map.put("x-dead-letter-routing-key","phone.code.dead");
       map.put("x-message-ttl",30000);
       return new Queue("phone_code_queue",true,false,false,map);
   }
   @Bean
    public TopicExchange topicExchange(){
       return new TopicExchange("phone_code_exchange");
   }
   @Bean
    public Binding queueBingToExchange(){
       return BindingBuilder.bind(queue()).to(topicExchange()).with("phone.#");
   }
    @Bean
    public Queue DeadQueue(){
        return new Queue("phone_code_dead_queue",true,false,false);
    }
    @Bean
    public TopicExchange topicDeadExchange(){
        return new TopicExchange("phone_code_dead_exchange");
    }
    @Bean
    public Binding queueBingToExchangeDead(){
        return BindingBuilder.bind(DeadQueue()).to(topicDeadExchange()).with("phone.code.dead");
    }

    /**
     * 对款订单的
     * @return
     */
    @Bean
    public Queue queue2(){

        return new Queue("refund_code_queue",true,false,false);
    }
    @Bean
    public TopicExchange topicExchange2(){
        return new TopicExchange("refund_code_exchange");
    }
    @Bean
    public Binding queueBingToExchange2(){
        return BindingBuilder.bind(queue2()).to(topicExchange2()).with("refund.#");
    }
}
